<template>
  <div>
    <van-search autofocus v-model="kw" placeholder="请输入搜索关键词" />
    <show-list :arr="arr"></show-list>
  </div>
</template>

<script>
import { reqsearch } from "../../http/http";

export default {
  data() {
    return {
      // 1.关键词
      kw: "",
      // 2.搜索的结果
      arr: [],
    };
  },
  watch: {
    // 3.监听kw
    kw() {
      if (this.kw === "") {
        this.arr = [];
        return;
      }
      reqsearch({
        keywords: this.kw,
      }).then((res) => {
        if (res.data.code == 200) {
          this.arr = res.data.list ? res.data.list : [];
        }
      });
    },
  },
};
</script>

<style>
</style>